package com.ruoyi.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.HosWard;
import com.ruoyi.hospital.service.IHosWardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病房信息Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@RestController
@RequestMapping("/hospital/ward")
public class HosWardController extends BaseController
{
    @Autowired
    private IHosWardService hosWardService;

    /**
     * 查询病房信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:ward:list')")
    @GetMapping("/list")
    public TableDataInfo list(HosWard hosWard)
    {
        startPage();
        List<HosWard> list = hosWardService.selectHosWardList(hosWard);
        return getDataTable(list);
    }

    /**
     * 查询所有病房
     * @return
     */
    @PreAuthorize("@ss.hasPermi('hospital:ward:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll() {
        return AjaxResult.success(hosWardService.selectHosWardList(null));
    }

    /**
     * 导出病房信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:ward:export')")
    @Log(title = "病房信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HosWard hosWard)
    {
        List<HosWard> list = hosWardService.selectHosWardList(hosWard);
        ExcelUtil<HosWard> util = new ExcelUtil<HosWard>(HosWard.class);
        util.exportExcel(response, list, "病房信息数据");
    }

    /**
     * 获取病房信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:ward:query')")
    @GetMapping(value = "/{wardId}")
    public AjaxResult getInfo(@PathVariable("wardId") Long wardId)
    {
        return success(hosWardService.selectHosWardByWardId(wardId));
    }

    /**
     * 新增病房信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:ward:add')")
    @Log(title = "病房信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HosWard hosWard)
    {
        return toAjax(hosWardService.insertHosWard(hosWard));
    }

    /**
     * 修改病房信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:ward:edit')")
    @Log(title = "病房信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HosWard hosWard)
    {
        return toAjax(hosWardService.updateHosWard(hosWard));
    }

    /**
     * 删除病房信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:ward:remove')")
    @Log(title = "病房信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wardIds}")
    public AjaxResult remove(@PathVariable Long[] wardIds)
    {
        return toAjax(hosWardService.deleteHosWardByWardIds(wardIds));
    }
}
